<?php
$this->layout()->disableLayout();
switch ($this->type) {
	case "javascript":
?>
// Загружаем все необходимые скрипты
dojo.xhrGet({
		url: '/cms/scripts/Popup.js',
		handleAs: "javascript",
		sync: true
	});
dojo.xhrGet({
		url: '/cms/scripts/tabWidget.js',
		handleAs: "javascript",
		sync: true
	});


new mfTabWidget('groupAddTabs');

dojo.query('#addGroupCloseBtn, #addGroupBackTab')
	.onclick(function () {
			dojo.destroy('addGroupBox');
			dojo.query('#groupListBox').removeClass('isHidden');
			dojo.destroy(addGroupStylesheet);
		});
		
dojo.query('#addGroupSubmitBtn').onclick(
	function () {
		dojo.xhrPost({
				url: '/cms/admingroup/<?= $this->mode ?>/type/save/id/<?= $this->group_id ?>',
				load: function(response, ioArgs) {
						if (response['ok']=='1') {
							dojo.destroy('addGroupBox');
							dojo.query('#groupListBox').removeClass('isHidden');
							dojo.destroy(addGroupStylesheet);
							dojo.publish('onsaveok',[]);
						} else {
							for (var inp in response) {
								if (!dojo.byId(inp)) {
									break;
								}
								dojo.query(dojo.byId(inp))
									.addClass('modalInputError')
									.connect('onkeydown', function () {
											dojo.query(this).removeClass('modalInputError');
										});
								var exclamTrigger = dojo.create('img',{className:'errorBulb isActive',src: '/cms/images/exclamation_frame.png'},inp,'after');
								var tip = dojo.create('div',{className:'splashHint',innerHTML:response[inp]},exclamTrigger,'after');
								new PopupArea(exclamTrigger,tip,PopupAreaAdaptors.mouseOverSplashUnderTrigger);
								var emptyOldPopups = function (trigger,tiptip) {
										dojo.query('#addGroupSubmitBtn').onclick(
											function () {
												dojo.destroy(trigger);
												dojo.destroy(tiptip);
											});
									};
								emptyOldPopups(exclamTrigger,tip);
							} 
						}
					},
				error: function (response, ioArgs){
						alert("An error occurred, with response: " + response);
						return response;
					},
				form: 'addGroupForm',
				handleAs:"json",
				sunc: true
			});
		
	});
	
var addGroupStylesheet = dojo.create('link',{rel:'stylesheet',type:'text/css',href:'/cms/admingroup/<?= $this->mode ?>/type/css/id/<?= $this->group_id ?>/style.css'},dojo.query('head')[0]);
<?php 
		break;
	case "css":
?>
.labelBox {
	width: 150px;
}
.inputBox input, .inputBox textarea {
	width: 300px;
}
.modalControlsBox {
	padding-left: 160px;
}

h1 {
	padding-left: 154px;
}
.splashHint {
	max-width: 350px;
}
.errorBulb {
	padding-left: 4px;
}
<?php
		break;
	case "html":
?>
<ul id="groupAddTabs">
  <li><a class="isActive back" id="addGroupBackTab">Назад к списку групп</a></li>
  <li class="active"><a><?= $this->mode=='edit' ? 'Изменение группы' : 'Добавление группы' ?></a></li>
</ul>
<div class="modalContent">
  <h1><?= $this->mode=='edit' ? 'Изменение группы' : 'Добавление группы' ?></h1>
  <form id="addGroupForm">
    <div class="antifloat"></div>
    <div class="labelBox">Название:</div>
    <div class="inputBox">
    <input name="name" type="text" class="modalInput" id="name" value="<?= $this->name ?>" /></div>
    <div class="antifloat"></div>
    <div class="labelBox">Примечание:</div>
    <div class="inputBox">
      <textarea name="summary" rows="5" class="modalInput" id="summary"><?= htmlspecialchars($this->summary) ?></textarea>
    </div>
    <div class="antifloat"></div>
  </form>
</div>
<div class="modalControls">
  <div class="controllGrad"></div>
  <div class="modalControlsBox">
    <input type="button" class="okButton" value="Сохранить" id="addGroupSubmitBtn" />
    <input type="button" class="okButton" value="Закрыть" id="addGroupCloseBtn" />
  </div>
</div>

<?php 	
		break;
	
	default:
?>

<?php 
	break;
}
?>